var vm = new Vue({
	el:'#vue_body',
	data:{
		q:{
			key: null
		},
		showList: true,
		title: null,
		compList: [
		  {name: 'Base(SpringBoot+配置中心+日志规范等)', value: 'base'},
		  {name: 'DB套件(mysql+mybatis+mapper)', value: 'dbbase'},
		  {name: '服务化：HTTP RESTful API', value: 'web'},
		  {name: '服务化：Dubbo生产端', value: 'dubbo-p'},
		  {name: '服务化：Dubbo消费端', value: 'dubbo-c'},
		  {name: '普通Web+页面', value: 'web-s'},
		  {name: '后管服务端（可接独立前端或嵌入式前端）', value: 'admin'},
		  {name: '后管嵌入式前端（vuejs+layui）', value: 'admin-layui'},
		  {name: '消息队列Kafka', value: 'kafka'},
		  {name: '对象存储FastDFS', value: 'hilodfs'},
		  {name: '缓存Redis', value: 'redis'},
		  {name: 'API文档Swagger', value: 'swagger'}
		],
		btype: null,
		config: {
		  basePackage: null,
		  useType: null,
		  compList: []
		}
	},
	methods: {
	  test: function () {
      if(this.config.useType==0) {
        this.config.compList=['base', 'dbbase', 'web-s', 'admin', 'admin-layui'];
        this.btype = 'admin';
      } else if(this.config.useType==1) {
        this.config.compList=['base', 'dbbase', 'dubbo-p'];
        this.btype = 'dubbo';
      } else if(this.config.useType==2) {
        this.config.compList=['base', 'dbbase', 'web-s'];
        this.btype = 'web';
      }
    },
	  generator: function() {
	    if(!vm.config.artifactId) {
        layer.alert("项目标识artifactId不能为空");
        return;
      }
      if(!vm.config.basePackage) {
          layer.alert("项目包名不能为空");
          return;
      }
      if(!vm.config.useType) {
        layer.alert("类型不能为空");
        return;
      }
      
      if(vm.config.compList.length==0) {
        layer.alert("请选择组件");
        return;
      }
      
      layer.msg('请稍等，大约需要10~~60秒', {
        time: 4000, //20s后自动关闭
        btn: ['明白了', '知道了']
      });
    
      var url = "/app/gen/by-type";
      var form = $("<form></form>").attr("action", url).attr("method", "post");
      // <input name="tables" value="${tableNames}" />
      form.append($("<input></input>").attr("type", "hidden").attr("name", "useType").attr("value", vm.btype));
      form.append($("<input></input>").attr("type", "hidden").attr("name", "basePackage").attr("value", "com.zollty." + vm.config.basePackage));
      form.append($("<input></input>").attr("type", "hidden").attr("name", "artifactId").attr("value", vm.config.artifactId));
      form.appendTo('body').submit().remove();
    },
		saveOrUpdate: function (event) {
		    if(!vm.config.artifactId) {
            layer.alert("项目标识artifactId不能为空");
            return;
        }
        if(!vm.config.basePackage) {
            layer.alert("项目包名不能为空");
            return;
        }
        if(!vm.config.useType) {
          layer.alert("类型不能为空");
          return;
      }
        
			var url = vm.config.id == null ? "../sys/config/save" : "../sys/config/update";
			$.ajax({
				type: "POST",
			    url: url,
			    data: JSON.stringify(vm.config),
			    success: function(r){
			    	if(r.success){
						alert('操作成功', function(index){
							vm.reload();
						});
					}else{
						alert(r.msg);
					}
				}
			});
		}
	
	}
});
